package com.chandra.pos.employee.service.impl;

/* @(#) EmployeeServiceImpl.java
 * Copyright 2013 - 2015 QatarAirways Group. All Rights Reserved.
 *
 * This Software is the proprietary information of QR Group
 * Use is subject to License terms.
 * Created by T4671 on 18/03/2015.
 */


import com.chandra.pos.employee.model.EmployeeFilter;
import com.chandra.pos.employee.model.EmployeeList;
import com.chandra.pos.employee.model.EmployeeModel;
import com.chandra.pos.employee.service.EmployeeRole;
import com.chandra.pos.employee.service.EmployeeService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import javax.persistence.EntityNotFoundException;

@Service
public class EmployeeServiceImpl implements EmployeeService {


    @Autowired
    EmployeeRole employeeRole;

    @Autowired
    private PasswordEncoder passwordEncoder;


    @Override
    public EmployeeModel saveEmployee(EmployeeModel employeeModel) {

        employeeModel.setPassword(passwordEncoder.encode(employeeModel.getPassword()));
        return employeeRole.saveEmployee(employeeModel);
    }

    @Override
    public EmployeeModel updateEmployee(EmployeeModel employeeModel) throws EntityNotFoundException {
        return employeeRole.updateEmployee(employeeModel);
    }

    @Override
    public EmployeeList searchEmployee(EmployeeFilter employeeModel) {
        return employeeRole.searchEmployee(employeeModel);
    }

    @Override
    public EmployeeModel getByUserName(String userName) throws EntityNotFoundException {
        return employeeRole.getByUserName(userName);
    }

    @Override
    public EmployeeModel getEmployeeDetail(EmployeeFilter filter) throws EntityNotFoundException {


            return employeeRole.getEmployeeDetail(filter);


    }
}
